import App from '@/App'
import { createHashRouter } from 'react-router-dom'

import { lazy, ReactNode, Suspense } from 'react'

export interface Route {
  path: string
  name: string
  element: ReactNode
  children?: Route[]
  auth?: boolean
}
const Login = lazy(() => import('@/pages/login/index'))
const Wait = lazy(() => import('@/pages/wait/index'))
const Exam = lazy(() => import('@/pages/exam/index'))
const Finished = lazy(() => import('@/pages/finished/index'))
export const routes: Route[] = [
  {
    path: '/',
    name: 'app',
    element: <App></App>,
    children: [
      {
        path: 'login',
        name: 'login',
        auth: false,
        element: (
          <Suspense fallback={<div>加载中...</div>}>
            <Login></Login>
          </Suspense>
        ),
      },
      {
        path: 'wait',
        name: 'wait',
        element: (
          <Suspense fallback={<div>加载中...</div>}>
            <Wait></Wait>
          </Suspense>
        ),
        auth: true,
      },
      {
        path: 'exam',
        name: 'exam',
        element: (
          <Suspense fallback={<div>加载中...</div>}>
            <Exam></Exam>
          </Suspense>
        ),
        auth: true,
      },
      {
        path: 'finished',
        name: 'finished',
        element: (
          <Suspense fallback={<div>加载中...</div>}>
            <Finished></Finished>
          </Suspense>
        ),
        auth: true,
      },
    ],
  },
]
const router = createHashRouter(routes)

export default router
